//
//  SINASearchLocationViewController.m
//  PlanTech
//
//  Created by  androidlongs on 2018/6/21.
//  Copyright © 2018年  androidlongs. All rights reserved.
//

#import "SINASearchLocationViewController.h"
#import "SINACircularBeadUtils.h"

@interface SINASearchLocationViewController ()<UITextFieldDelegate>
@property(strong,nonatomic)UITextField *searchTextField;
@end

@implementation SINASearchLocationViewController

- (void)viewDidLoad {
    [super viewDidLoad]; UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(-20, 0, mainW-mainW/5, 32)];
    UIColor *color =  [UIColor colorWithRed:(255/255.0)  green:(255/255.0)  blue:(255/255.0)  alpha:0.5];
    [titleView setBackgroundColor:color];
    
    self.navigationItem.titleView = titleView;
    
    [SINACircularBeadUtils makeCircularBead:6 andView:titleView];
    
    
    //search_icon
    
    UIImageView *iv = [[UIImageView alloc] init];
    iv.backgroundColor = [UIColor clearColor];
    iv.image = [UIImage imageNamed:@"search_icon"];
    iv.frame = CGRectMake(10, 35/2-9, 16, 18);
    [titleView addSubview:iv];
    
    CGRect rect = CGRectMake(CGRectGetMaxX(iv.frame)+12, CGRectGetHeight(titleView.frame)/2-11, CGRectGetWidth(titleView.frame)-CGRectGetMaxX(iv.frame)-24, 22);
    UITextField *textField = [[UITextField alloc] initWithFrame:rect];
    textField.placeholder = @"搜索";
    textField.textColor=[UIColor whiteColor];
    textField.font=[UIFont systemFontOfSize:15];
    [titleView addSubview:textField];
     [textField becomeFirstResponder];
    self.searchTextField = textField;
    
    textField.returnKeyType = UIReturnKeySearch;//变为搜索按钮
    
    textField.delegate = self;
    
    self.view.backgroundColor = [UIColor colorWithHexString:@"#eeeeee"];
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField

{
    
    [self.view endEditing:YES];
    
    NSString *searchContent = self.searchTextField.text;
    if (searchContent==nil||[searchContent isEqualToString:@""]) {
        [YPXToastView showToastViewWithText:@"请输入搜索内容" andDuration:0 andParentView:self.view];
    }else{
        
        NSDictionary *dict =[[NSDictionary alloc] initWithObjectsAndKeys:searchContent,@"searchKey", nil];
        NSNotification *notification =[NSNotification notificationWithName:notificationKeySearchLocation object:nil userInfo:dict];
        [[NSNotificationCenter defaultCenter] postNotification:notification];
        
        [self.navigationController popViewControllerAnimated:YES];
    }
    
    NSLog(@"点击了搜索");
    
    return YES;
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
